package com.bhoethang.rabbit.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author EDZ
 */
@Configuration
public class RabbitOrderConfig {

    /**dead*/
    public static final String LOCK_MERCHANT_DEAD_QUEUE = "lock_merchant_dead_queue";

    public static final String LOCK_MERCHANT_DEAD_EXCHANGE = "lock_merchant_dead_exchange";

    public static final String LOCK_MERCHANT_BINDING_KEY = "dead.#";

    @Bean
    public Exchange lockMerchantDeadExchange(){
        return ExchangeBuilder.topicExchange(LOCK_MERCHANT_DEAD_EXCHANGE).durable(false).build();
    }

    @Bean
    public Queue lockMerchantDeadQueue(){
        return QueueBuilder.durable(LOCK_MERCHANT_DEAD_QUEUE).build();
    }

    @Bean
    public Binding lockMerchantBinding(){

        return new Binding(LOCK_MERCHANT_DEAD_QUEUE,Binding.DestinationType.QUEUE,
                LOCK_MERCHANT_DEAD_EXCHANGE,LOCK_MERCHANT_BINDING_KEY ,null);
    }




    public static final String NEW_MERCHANT_QUEUE = "new_merchant_queue";

    public static final String NEW_MERCHANT_EXCHANGE = "new_merchant_exchange";

    public static final String NEW_MERCHANT_ROUTING_KEY = "alive.#";

    @Bean
    public Exchange newMerchantExchange(){
        return new TopicExchange(NEW_MERCHANT_EXCHANGE,true,false);
    }


    @Bean
    public Queue newMerchantQueue(){
        Map<String,Object> arg = new HashMap<>();
        arg.put("x-message-ttl",10000);
        arg.put("x-dead-letter-exchange",LOCK_MERCHANT_DEAD_EXCHANGE);
        arg.put("x-dead-letter-routing-key","dead.order");
        return QueueBuilder.durable(NEW_MERCHANT_QUEUE).withArguments(arg).build();
    }



    @Bean
    public Binding newMerchantBinding(){
        return new Binding(NEW_MERCHANT_QUEUE,Binding.DestinationType.QUEUE,
                NEW_MERCHANT_EXCHANGE,NEW_MERCHANT_ROUTING_KEY,null);
    }
}
